(function ($) {
    $.fn.popup = function (g) {
        g = $.extend({}, g);
        g = $.extend(true, {}, g);
        
        var div = window.parent.document.createElement('div');
        div.id = 'video'+ g.unique;
        var divc = window.parent.document.createElement('div');
        divc.innerHTML = g.video;
        var close = window.parent.document.createElement('img');
        close.src = 'plugins/vdp/assets/de.png';
        close.id = 'close'+g.unique;
        divc.appendChild(close);
        div.appendChild(divc);
        window.parent.document.body.appendChild(div);
        
        if($('#video'+g.unique+' embed', window.parent.document).length>0){
          var ewidth = $('#video'+g.unique+' embed',window.parent.document).attr("width");
          var eheight = $('#video'+g.unique+' embed',window.parent.document).attr("height");
        } else {
          var ewidth = $('#video'+g.unique+' iframe',window.parent.document).attr("width");
          var eheight = $('#video'+g.unique+' iframe',window.parent.document).attr("height");
        }
        console.log(ewidth);
        var swidth = window.parent.document.documentElement.clientWidth;
        var sheight = window.parent.document.documentElement.clientHeight;

          $('#img'+g.unique).css({
            'width':'290px',
            'height':'120px',
            'cursor':'pointer'
            });
          $('#video'+g.unique,window.parent.document).css({
            'width':'100%',
            'height':'500%',
            'position':'absolute',
            'zIndex':'20000',
            'top':'0',
            'left':'0',
            'background':'url(plugins/vdp/assets/back.png) repeat',
            'display':'none',
            'textAlign':'center'
          });
          $('#video'+g.unique+' div',window.parent.document).css({
            'width':ewidth,
            'height':eheight,
            'position':'fixed',
            'zIndex':'3000',
            'top':(sheight-eheight)/2,
            'left':(swidth-ewidth)/2
          });
          $('#close'+g.unique,window.parent.document).css({
            'cursor':'pointer',
            'position':'absolute',
            'zIndex':'40000',
            'top':'-7px',
            'right':'-7px'
          });
          $('#img'+g.unique).click(function(){
            $('#video'+g.unique,window.parent.document).css('display','block');
            window.parent.document.body.style.overflow = "hidden";
          });
          $('#close'+g.unique,window.parent.document).click(function(){
            $('#video'+g.unique,window.parent.document).css('display','none');
            window.parent.document.body.style.overflow = "auto";
          });
    };
})(jQuery);